package com.example.jaden.myapplication;

import static java.sql.Types.NULL;

import java.util.Random;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ResultActivity extends android.app.Activity {
    private TextView textview;
    private Button bt;
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.result);

        bt=findViewById(R.id.quit);
        bt.setOnClickListener(view2);

        bt=findViewById(R.id.back);
        bt.setOnClickListener(view1);

        textview=(TextView)findViewById(R.id.result);
        Intent intent=getIntent();
        Bundle bundle=intent.getExtras();
        int ren=bundle.getInt("quan");
        //电脑出的拳
        Random random=new Random();
        int cpu=random.nextInt(3)+1;
        String result=compare(ren ,cpu);
        textview.setText(result);
    }
    private String compare(int ren ,int cpu) {
        StringBuffer show = new StringBuffer();
        {
            if (ren == NULL) {
                show.append("\u3000\u3000" + getResources().getString(R.string.xuan));
            } else
                show.append("结果:\n\n" + "\u3000\u3000" + "二狗:" + xianshi(ren) + "  VS  " + "邪剑仙:" + xianshi(cpu) + "\n\n\n");
                if (ren == cpu) {
                    show.append(getResources().getString(R.string.pingju));
                } else if (ren == 1 && cpu == 3) {
                    show.append(getResources().getString(R.string.AIwin));
                } else if (ren == 3 && cpu == 1) {
                    show.append(getResources().getString(R.string.Uwin));
                } else if (ren < cpu&&ren!=NULL) {
                    show.append(getResources().getString(R.string.Uwin));
                } else if (ren > cpu) {
                    show.append(getResources().getString(R.string.AIwin));
                }
                return show.toString();
            }
        }
    private String xianshi(int id){

        switch (id) {
            case 1:
                return getResources().getString(R.string.s);
            case 2:
                return getResources().getString(R.string.j);
            case 3:
                return getResources().getString(R.string.b);
            default:
                break;
        }
        return null;
    }
    private View.OnClickListener view1=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setClass(ResultActivity.this, RunActivity.class);
            startActivity(intent);
        }

    };
    private View.OnClickListener view2=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent();
            intent.setClass(ResultActivity.this, MainActivity.class);
            startActivity(intent);
        }

    };
    }